package com.fansl.koala.quickdev.common.enums;

import com.fansl.koala.quickdev.common.exception.EnumNotfoundException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author fansl
 * @Description: 菜单类型
 * @date 2020/3/30 18:46
 */
@Getter
@AllArgsConstructor
public enum  MenuTypeEnum {
    /**
     * 菜单
     */
    MENU("0","菜单"),
    BUTTON("1","按钮"),
    ;
    private final String code;
    private final String message;

    /**
     * 根据code获取枚举值，未找到抛出异常
     * @param code 代码
     * @return 枚举成员
     */
    public static MenuTypeEnum findByCode(String code) {
        return Arrays.stream(MenuTypeEnum.values())
                .filter(enumMember -> enumMember.getCode().equals(code))
                .findFirst()
                .orElseThrow(EnumNotfoundException::new);
    }
}
